﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using System.Data;

namespace ZLDC.Estate.UM
{
    public partial class AddFlow : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                int id = _Request.GetInt("id", 0);
                if (id > 0)
                {
                    DataSet ds = ZLDC.Topo.BLL.Estate.CallBoardBLL.SelectDetailsById(id);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        txtContent.Value = ds.Tables[0].Rows[0]["content"].ToString();
                    }
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id=_Request.GetInt("id",0);
            string Content = this.txtContent.Value.Trim().Replace("\n", "");//内容
            string msg_title="";
            int type = 1;
            string reader="";
            //如果是分行经理，保留最新一条信息   每人保留两条
            if (_Utility.GetInfoBySession().m_sStation == "分行经理" || _Utility.GetInfoBySession().m_sStation == "区域经理") 
            {
                ZLDC.Topo.BLL.Estate.CallBoardBLL.DeleteMsg();
            }

           string outmsg= ZLDC.Topo.BLL.Estate.CallBoardBLL.p_call_board_save(id, msg_title, Content, type, reader);

           if (outmsg == "添加成功" || outmsg == "更新成功")
           {    
               ZLDC.Topo.BLL.Estate.CallBoardBLL.DeleteMsgList();//发布公告时  删除历史数据  保留最后十条
               ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>window.close();</script>");
           }
           else
           {
               ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('" + outmsg + "')</script>");
           }
        }
    }
}
